home *** CD-ROM | disk | FTP | other *** search
- /* PRINT/CCC - General File Printer - March 21, 1983 */
- /* last changed: November 24, 1983 -- jwk */
-
- #include stdio/csh
-
- #define PAGSIZ 66
- #define MAXTXT PAGSIZ-6
- #define MAXWID 80
- #define TABS 4
- #option INLIB
-
- FILE *fp;
- int byte, pgnbr, lnbr, col;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- fprintf(stderr,"%c%c\n",28,31); /* CLS */
- msg("PRINT4 -- Print File(s)","by page");
- if (argc == 1) {
- dofile(stdin, "");
- }
- else {
- while (--argc) {
- ucs(*++argv);
- if (fp = fopen(*argv,"r")) {
- dofile(fp, *argv);
- fclose(fp);
- }
- else
- msg("CAN'T OPEN",*argv);
- }
- }
- }
-
- ucs(strng) /* force STRNG to upper case */
- char *strng;
- {
- while (*strng) {
- *strng = toupper(*strng);
- ++strng;
- }
- }
-
- dofile(file, nptr) /* process one file */
- FILE *file;
- char *nptr;
- {
- msg("Processing file",nptr);
- lnbr=col=0;
- pgnbr=1;
- while (doline(file, nptr)); /* until EOF */
- endpage(); /* flush final page */
- msg("Finished",nptr);
- }
-
- doline(file, nptr) /* process one line */
- FILE *file;
- char *nptr;
- {
- cktop(nptr);
- while ((byte=getc(file)) != EOF) {
- out(byte);
- if (byte == EOL || byte == 10) {
- ++lnbr;
- col = 0;
- return (TRUE);
- }
- }
- return (FALSE);
- }
-
- cktop(nptr) /* margin control */
- char *nptr;
- {
- char aray[10];
- if (lnbr > MAXTXT) { /* at bottom */
- endpage();
- }
- if (lnbr == 0) { /* at top of a page */
- slew(3);
- putstr(nptr);
- tabto(32);
- time(aray);
- putstr(aray);
- tabto(56);
- date(aray);
- putstr(aray);
- tabto(72);
- putstr(" Page ");
- itoa(pgnbr++,aray);
- putstr(aray);
- slew(3);
- }
- }
-
- endpage() /* flush out a full or used page */
- {
- if (lnbr) { /* part of page used anyway */
- while (lnbr++ < PAGSIZ) {
- putchar(' ');
- putchar(EOL);
- }
- lnbr = col = 0;
- }
- }
-
- out(c) /* output a byte */
- char c;
- {
- if (c == EOL || c == 10) {
- if (!col) putchar(' ');
- putchar(EOL);
- col = 0;
- }
- else {
- if (!col) tabto(8);
- if (c == 9) tabto(col+TABS);
- else {
- putchar(c);
- ++col;
- }
- if (col > MAXWID) {
- if (++lnbr > MAXTXT) endpage();
- else {
- col = 0;
- putchar(EOL);
- }
- }
- if (!col) {
- printf("+++++");
- tabto(8);
- }
- }
- if (lnbr > MAXTXT) endpage();
- }
-
- msg(s1,s2) /* message to STDERR */
- char *s1, *s2;
- {
- fprintf(stderr,"%s %s\n",s1,s2);
- }
-
- tabto(n)
- int n;
- {
- if (n > MAXWID) n = MAXWID;
- n = n & (-TABS);
- while (col++ < n) putchar(' ');
- --col;
- }
-
- putstr(strng) /* send STRNG to STDOUT */
- char *strng;
- {
- while (*strng)
- out(*strng++);
- }
-
- slew(n) /* send N EOL's */
- int n;
- {
- col = 0;
- while(n-- > 0) {
- out(EOL);
- if (++lnbr >= PAGSIZ) return;
- }
- }
-
- /* END OF PROGRAM */
-